package com.aha.dataanalyzeandview.utils.avro;

import org.apache.avro.Schema;
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericRecord;

import java.io.File;
import java.io.IOException;

/******************************
 * Project:           avro-demo
 * FileName:          CreateUserByAvro.java
 * ClassName:         CreateUserByAvro
 * Time:              2020/5/19 23:44
 * Version:           1.00
 * Author:            努力就是魅力
 * Description:       TODO
 ******************************/
public class CreateUserByAvsc {

    public static void main(String[] args) {
        Schema schema = null;
        try {
            schema = new Schema.Parser().parse(new File("E:\\code\\data-analyze-and-view\\doc\\file\\User.avsc"));
        } catch (IOException e) {
            e.printStackTrace();
        }


        GenericRecord user1 = new GenericData.Record(schema);
        user1.put("name", "Alyssa");
        user1.put("favorite_number", 256);
// Leave favorite color null

        GenericRecord user2 = new GenericData.Record(schema);
        user2.put("name", "Ben");
        user2.put("favorite_number", 7);
        user2.put("favorite_color", "red");


        System.out.println(user1);
        System.out.println(user2);
    }
}
